package com.xoms.admin.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.admin.model.AccountBean;
import com.xoms.admin.persist.dao.AccountDao;
import com.xoms.util.StringUtil;

@Repository
public class AccountImpl extends BaseImpl implements AccountDao {
	
	final String NAME_SPACE = NAME_SPACE_HEADER + ".AccountMapper";

	@Override
	public AccountBean selectOneByPhone(String phoneNum) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneByPhone", phoneNum);
	}

	@Override
	public AccountBean selectOneByAccid(String accid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneById", accid);
	}
	
	@Override
	public int selectCount(String key, int roleId, int deptId) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		params.put("roleId", roleId);
		params.put("deptId", deptId);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", params);

	}

	@Override
	public List<AccountBean> selectList(String key, int roleId, int deptId, int page, int pageSize) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pageSize);
		params.put("length", pageSize);
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		params.put("roleId", roleId);
		params.put("deptId", deptId);

		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", params);

	}
	
	@Override
	public int insert(AccountBean account) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", account);
	}

	@Override
	public int update(AccountBean account) {
		return sqlSessionTemplate.update(NAME_SPACE + ".update", account);

	}
	
	@Override
	public int updateLastLoginTime(String accid) {
		return sqlSessionTemplate.update(NAME_SPACE + ".updateLastLoginTime", accid);
	}

	@Override
	public int updatePwd(AccountBean temp) {
		return sqlSessionTemplate.update(NAME_SPACE + ".updatePwd", temp);
	}


	@Override
	public int updateStatus(String accid, int status) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("accid", accid);
		params.put("status", status);
		return sqlSessionTemplate.update(NAME_SPACE + ".updateStatus", params);
		
	}


}
